#pragma once
#include "../Render/Text.h"
#include "../Render/Texture.h"
#include "SpaceObject.h"

namespace cy_univerX
{
namespace world2d
{

	class CTextNode:public CSpaceNode
	{
	protected:
		std::string					m_Text;
		math::CColor4f				m_Color;
		render::CTextFont			m_Font;
		mutable math::CVector2f		m_LocalSize;
		mutable bool				m_Dirty;
		mutable render::CTexture2D *m_Texture;

		void UpdateTextTexture()const;
	public:
		explicit CTextNode(const render::CTextFont&font, const std::string&text = "", CSpaceNode* parent = 0);
		~CTextNode();

		math::CColor4f& Color()
		{
			return m_Color;
		}
		const math::CColor4f &Color()const
		{
			return m_Color;
		}

		const std::string &GetText()const
		{
			return m_Text;
		}
		void SetText(const std::string& text)
		{
			m_Text = text;
			m_Dirty = true;
		}

		const render::CTextFont& GetFont()const
		{
			return m_Font;
		}
		void SetFont(const render::CTextFont&font)
		{
			if (m_Font == font)
				return;
			m_Font = font;
			m_Dirty = true;
		}

		const math::CVector2f& GetLocalSize()const
		{
			if (m_Dirty)
				UpdateTextTexture();
			return m_LocalSize;
		}

		virtual void Render(const float& window_w, const float& window_h, render::CSimpleEffectBase* eff)const;
	};

}
}